<template>
  <div class="base-content">
    <div class="account_base">
      <el-row>
        <el-col :span="9" style="padding-right: 25px">
          <div class="base_info_box">
            <h5>基本信息</h5>
            <div class="custom_wallet">
              <div class="item_col custom_alance">
                <div class="pull-right">
                  <span
                    class="text_action_blue"
                    title="设置余额提醒"
                    @click="setBalanceAlert"
                    >设置余额提醒</span
                  >
                  <el-dialog
                    :close-on-click-modal="false"
                    title="设置余额预警值"
                    :visible.sync="dialogBalanceVisible"
                    width="30%"
                  >
                    <el-form
                      :model="form1"
                      :rules="rules"
                      ref="form1"
                      @submit.native.prevent
                    >
                      <el-form-item
                        label="账户余额预警值(元)"
                        :label-width="formLabelWidth"
                        prop="price"
                      >
                        <el-input
                          v-model.trim="form1.price"
                          auto-complete="off"
                        ></el-input>
                      </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                      <el-button class="primary_btn" @click="cancleSetBalance"
                        >取 消</el-button
                      >
                      <el-button
                        type="primary"
                        class="primary_btn"
                        @click="setBalance"
                        >确 定</el-button
                      >
                    </div>
                  </el-dialog>
                </div>
                <div class="field" :class="[ifAlert ? 'accFee' : 'accOweFee']">
                  余额：
                </div>
                <div
                  class="info uc_balance"
                  :class="[ifAlert ? 'accFee' : 'accOweFee']"
                >
                  {{ balance }}
                </div>
              </div>
              <div class="item_col">
                <div class="field">
                  <el-button
                    type="primary"
                    class="primary_btn"
                    @click="openAccountPay"
                    >充值</el-button
                  >
                  <el-dialog
                    :close-on-click-modal="false"
                    title="账户充值"
                    :visible.sync="dialogPayVisible"
                  >
                    <div class="payTabs config">
                      <div class="rechargeAmount">
                        <!--<span class="headMargin"></span>-->
                        <el-form
                          :model="bankPay"
                          :rules="rules1"
                          class="recharge_amount"
                          ref="form"
                          @submit.native.prevent
                        >
                          <el-form-item
                            prop="price"
                            label="充值金额（元）:"
                            :label-width="formLabelWidth2"
                          >
                            <el-input
                              v-model.trim="bankPay.price"
                              auto-complete="off"
                              style="max-width: 194px"
                            ></el-input>
                          </el-form-item>
                        </el-form>
                        <!--<span>元</span>-->
                      </div>
                      <h5 class="headMargin">支付方式：</h5>
                      <el-tabs
                        v-model.trim="activeName2"
                        @tab-click="handleClick"
                        style="overflow-y: auto"
                      >
                        <el-tab-pane label="个人网银" name="first">
                          <ul class="bank-list">
                            <li
                              v-for="(bank, index) in banks"
                              class="bank1"
                              v-show="bank.show"
                              @click="radioClick(index, 'bank1')"
                            >
                              <input
                                :id="bank.id"
                                type="radio"
                                class="jdradio"
                                :value="bank.value"
                                name="bank"
                                required
                              />
                              <label :for="bank.id">
                                <img
                                  width="125"
                                  height="28"
                                  :alt="$t('bank.' + bank.name)"
                                  :src="'/img/bank/' + bank.name + '.png'"
                                />
                              </label>
                            </li>
                          </ul>
                          <div class="pay-more" style="overflow: visible.sync">
                            <a
                              class="link-more"
                              href="#none"
                              @click="showMore(true)"
                              v-show="ifShowMore"
                              ><strong>更多银行</strong
                              ><i class="icon iconfont icon-zhankai1"></i
                            ></a>
                            <a
                              class="link-more"
                              href="#none"
                              @click="showMore(false)"
                              v-show="!ifShowMore"
                              ><strong>收起</strong
                              ><i class="icon iconfont icon-shouqi"></i
                            ></a>
                          </div>
                        </el-tab-pane>
                        <el-tab-pane label="企业网银" name="second">
                          <ul class="bank-list">
                            <li
                              v-for="(bank, index) in banks_enterprise"
                              class="bank2"
                              v-if="bank.show"
                              @click="radioClick(index, 'bank2')"
                            >
                              <input
                                :id="bank.id"
                                type="radio"
                                class="jdradio"
                                :value="bank.value"
                                name="bank"
                                required
                              />
                              <label :for="bank.id">
                                <img
                                  width="125"
                                  height="28"
                                  :alt="$t('bank.' + bank.name)"
                                  :src="'/img/bank/' + bank.name + '.png'"
                                />
                              </label>
                            </li>
                          </ul>
                        </el-tab-pane>
                        <el-tab-pane label="支付平台" name="third">
                          <ul class="bank-list">
                            <li
                              v-for="(bank, index) in banks_ali"
                              class="bank3"
                              v-if="bank.show"
                              @click="radioClick(index, 'bank3')"
                            >
                              <input
                                :id="bank.id"
                                type="radio"
                                class="jdradio"
                                :value="bank.value"
                                name="bank"
                                required
                              />
                              <label :for="bank.id">
                                <img
                                  width="125"
                                  height="28"
                                  :alt="$t('bank.' + bank.name)"
                                  :src="'/img/bank/' + bank.name + '.gif'"
                                />
                              </label>
                            </li>
                          </ul>
                        </el-tab-pane>
                      </el-tabs>
                    </div>
                    <div slot="footer" class="dialog-footer">
                      <el-button
                        class="primary_btn"
                        @click="dialogPayVisible = false"
                        >关 闭</el-button
                      >
                      <el-button
                        class="primary_btn"
                        type="primary"
                        @click="confirmAccountPay"
                        >确 定 支 付</el-button
                      >
                    </div>
                  </el-dialog>
                  <el-dialog
                    :close-on-click-modal="false"
                    title="账户充值"
                    :visible.sync="dialodPayEnd"
                  >
                    <div class="pay_end">
                      <p style="">
                        请您在新打开的网上银行页面进行支付，支付完成前请不要关闭该窗口
                      </p>
                      <p class="text-center">
                        <el-button
                          class="primary_btn"
                          type="primary"
                          @click="finishbankpay"
                          >支 付 完 成</el-button
                        >
                      </p>
                    </div>
                  </el-dialog>
                </div>
                <div class="info">
                  <span
                    title="充值记录"
                    class="text_action_blue"
                    @click="redirectUcenter('pay')"
                    >充值记录</span
                  >
                  <span
                    title="消费记录"
                    class="text_action_blue"
                    @click="redirectUcenter('cost')"
                    >消费记录</span
                  >
                  <span
                    title="申请发票"
                    class="text_action_blue"
                    @click="redirectUcenter('invoice')"
                    >申请发票</span
                  >
                </div>
              </div>
            </div>
            <div class="base_info_inner">
              <div class="item_col">
                <div class="pull-right">
                  <span class="dentity">{{ identityStatus }}</span>
                  <a href="#" v-show="ifidentity" @click="redirectUcenter('')"
                    >认证</a
                  >
                </div>
                <div class="field field_right">公司名称：</div>
                <div class="info">{{ information.companyName }}</div>
              </div>
              <div class="item_col">
                <div class="field field_right">账号：</div>
                <div class="info">{{ information.name }}</div>
              </div>
              <div class="item_col">
                <div class="pull-right">
                  <span
                    class="img_action_edit"
                    title="修改账户信息"
                    @click="editInfo"
                  >
                    <i class="icon iconfont icon-beizhu"></i>
                  </span>
                  <el-dialog
                    :close-on-click-modal="false"
                    title="修改账户信息"
                    :visible.sync="dialogAccountInfoVisible"
                    width="30%"
                  >
                    <el-form :model="form4" :rules="rules2" ref="infoForm">
                      <el-form-item
                        label="联系人"
                        :label-width="formLabelWidth1"
                      >
                        <el-input
                          v-model.trim="form4.name"
                          auto-complete="off"
                          style="width: 80%"
                        ></el-input>
                      </el-form-item>
                      <el-form-item
                        label="电话"
                        :label-width="formLabelWidth1"
                        prop="phone"
                      >
                        <el-input
                          v-model.trim="form4.phone"
                          auto-complete="off"
                          style="width: 80%"
                        ></el-input>
                      </el-form-item>
                      <el-form-item
                        label="邮箱"
                        :label-width="formLabelWidth1"
                        prop="email"
                      >
                        <el-input
                          v-model.trim="form4.email"
                          auto-complete="off"
                          style="width: 80%"
                        ></el-input>
                      </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                      <el-button
                        class="primary_btn"
                        @click="dialogAccountInfoVisible = false"
                        >取 消</el-button
                      >
                      <el-button
                        type="primary"
                        class="primary_btn"
                        @click="setAccountInfo"
                        >保存</el-button
                      >
                    </div>
                  </el-dialog>
                </div>
                <div class="field field_right">联系人：</div>
                <div class="info linkManName">
                  {{ information.linkManName }}
                </div>
              </div>
              <div class="item_col">
                <div class="field field_right">电话：</div>
                <div class="info linkManPhone">
                  {{ information.linkManPhone }}
                </div>
              </div>
              <div class="item_col">
                <div class="field field_right">邮箱：</div>
                <div class="info linkManEmail">
                  {{ information.linkManEmail }}
                </div>
              </div>
              <div class="item_col" v-if="!$store.state.oemObj.oemFlag">
                <div class="field field_right">
                  企业验证码
                  <span style="color: #ff6b6b">（用于APP登录）</span>：
                </div>
                <div class="info linkManEmail">{{ information.accountId }}</div>
              </div>

              <div
                class="sales_info text-info"
                v-show="information.salesUser.name"
              >
                <div
                  style="
                    display: inline-block;
                    margin-top: 15px;
                    color: #3a87ad;
                  "
                >
                  <span v-show="information.salesUser.name">
                    您的销售经理是：{{ information.salesUser.name }}
                    <span v-show="information.salesUser.linkManPhone">
                      ，联系电话：{{ information.salesUser.linkManPhone }}
                    </span>
                    <span v-show="information.salesUser.linkManEmail">
                      ，联系邮箱：{{ information.salesUser.linkManEmail }}
                    </span>
                  </span>
                </div>
              </div>
            </div>
            <div
              class="alert alert-block"
              :class="{ oem_7moor: $store.state.oemObj.oemFlag }"
            >
              温馨提示：<br />
              如需增加座席或使用企业版本，请联系七陌客服，邮箱：<strong>{{
                base64Email
              }}</strong
              >，电话：<strong>4001-113-114</strong><br />
            </div>
          </div>
        </el-col>
        <el-col :span="15" class="sub-right">
          <div class="panel panel-info">
            <div class="panel-heading">
              座席授权（Licence)
              <el-tooltip
                content="Licence用于控制座席的最大登录数量，不同版本的Licence功能会有差别"
                placement="bottom"
                effect="dark"
              >
                <span class="tip"
                  ><i class="iconfont icon-tixingweizhi"></i
                ></span>
              </el-tooltip>
              <!--<el-button type="primary" class="primary_btn licence" @click="addnewlicence">新增licence</el-button>-->
              <el-dialog
                :close-on-click-modal="false"
                title="新增licence"
                :visible.sync="dialogLicenceVisible"
                width="30%"
              >
                <p class="licencenotice">licence可以免费试用10天</p>
                <el-form
                  :model="licenceForm"
                  label-width="80px"
                  :rules="rules5"
                >
                  <el-form-item label="类型">
                    <el-select v-model.trim="licenceForm.type" placeholder="">
                      <el-option label="标准版" value="standard"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="节点" required>
                    <el-select
                      v-model.trim="licenceForm.node"
                      class="licence_pbx"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="(item, index) in pbxlist"
                        :label="item"
                        :value="item"
                        :key="index"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="单价">
                    <el-input
                      v-model.trim="licenceForm.price"
                      auto-complete="off"
                      disabled
                      style="width: 35%; min-width: 194px"
                      readonly
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="licence数量" prop="num">
                    <el-input-number
                      v-model.trim="licenceForm.num"
                      :min="1"
                      @change="licenceChange"
                      style="min-width: 194px"
                      size="mini"
                    ></el-input-number>
                  </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button
                    class="primary_btn"
                    @click="dialogLicenceVisible = false"
                    >关 闭</el-button
                  >
                  <el-button
                    type="primary"
                    class="primary_btn"
                    @click="addLicence"
                    >试 用</el-button
                  >
                </div>
              </el-dialog>
            </div>
            <el-table
              :data="tableData_licence"
              size="mini"
              style="width: 100%; margin-bottom: 20px"
            >
              <el-table-column prop="type" label="类型" width="120">
              </el-table-column>
              <el-table-column prop="price" label="价格(月/座席)">
              </el-table-column>
              <el-table-column prop="agentNum" label="座席数" width="80">
              </el-table-column>
              <el-table-column prop="status" label="状态" width="80">
              </el-table-column>
              <el-table-column prop="createTime" label="开通时间">
              </el-table-column>
              <el-table-column prop="deadline" label="到期时间">
              </el-table-column>
              <el-table-column label="操作">
                <template scope="scope">
                  <a
                    href="#"
                    class="opeLink"
                    v-show="scope.row.operation.showRenew"
                    @click="renew(scope.$index, scope.row)"
                    >续费</a
                  >
                  <a
                    href="#"
                    class="opeLink"
                    v-show="scope.row.operation.showRenewNum"
                    @click="renewNum(scope.$index, scope.row)"
                    >调整数量</a
                  >
                  <a href="#" style="display: none">变更状态</a>
                </template>
              </el-table-column>
            </el-table>
            <el-dialog
              :close-on-click-modal="false"
              title="licence续费"
              :visible.sync="dialogXufeiVisible"
            >
              <div class="licence_pay">
                <div class="well" style="padding: 0 19px">
                  <h2>
                    续费企业版
                    <small>
                      licence单价:
                      <span class="text-primary monthRent">{{ perCost }}</span
                      >元
                    </small>
                  </h2>
                  <p class="text-muted haveDate">
                    当前licence数<span class="text-primary">{{
                      licenceNum
                    }}</span
                    >，到期日期为<strong class="text-danger">{{
                      endDate
                    }}</strong>
                  </p>
                </div>
              </div>
              <el-form :model="feeForm" :rules="rules4" @submit.native.prevent>
                <el-form-item
                  label="时长"
                  :label-width="formLabelWidth"
                  prop="months"
                >
                  <el-input-number
                    v-model.trim="feeForm.months"
                    @change="handleChange"
                    size="mini"
                    :min="perCost ? 1 : 0"
                    :max="perCost ? Infinity : 0"
                  ></el-input-number>
                  <span class="month"> {{ licencePayTypeUnit }}</span>
                  <span class="price-tip" v-show="!perCost"
                    >当前价格不可以进行增购，请联系客服人员</span
                  >
                </el-form-item>
                <el-form-item label="费用" :label-width="formLabelWidth">
                  <span class="cost">{{ cost }}元</span>
                </el-form-item>
                <div class="notice">
                  <p>
                    您当前可支付余额为:<span>{{ paySum }}</span
                    >元,其中实际余额为:{{ actualBalance }},透支额度为{{
                      overdraw
                    }}
                  </p>
                  <p class="balance_not_enough" v-show="ifEnough">
                    您的账户余额不足，请立即充值。
                  </p>
                </div>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button
                  @click="dialogXufeiVisible = false"
                  class="primary_btn"
                  >关 闭</el-button
                >
                <el-button
                  type="primary"
                  @click="confirmPay"
                  class="primary_btn"
                  :disabled="!perCost"
                  >立即购买</el-button
                >
              </div>
            </el-dialog>
            <el-dialog
              :close-on-click-modal="false"
              title="调整licence数量"
              :visible.sync="dialogNumVisible"
            >
              <div class="licence_pay">
                <div class="well" style="padding: 0 19px">
                  <h2>
                    调整数量
                    <small>
                      licence单价:
                      <span class="text-primary monthRent">{{ perCost }}</span
                      >元
                    </small>
                  </h2>
                  <p class="text-muted haveDate">
                    当前licence数<span class="text-primary">{{
                      licenceNum
                    }}</span
                    >，到期日期为<strong class="text-danger">{{
                      endDate
                    }}</strong>
                  </p>
                </div>
              </div>
              <el-form :model="licenceNumForm" :rules="rules3" @submit.native.prevent>
                <el-form-item
                  label="当前licence数"
                  :label-width="formLabelWidth"
                  prop="licenceNumAdd"
                >
                  <el-input-number
                    v-model.trim="licenceNumForm.licenceNumAdd"
                    @change="handleChangeNum"
                    :min="1"
                    :max="oneLicenceShouldFee ? Infinity : licenceNum"
                    size="mini"
                  ></el-input-number>
                  <span class="price-tip" v-show="!oneLicenceShouldFee"
                    >当前价格不可以进行增购，请联系客服人员</span
                  >
                </el-form-item>
                <el-form-item label="增减数量" :label-width="formLabelWidth">
                  <span>{{ licenceNumForm.licenceNumAdd - licenceNum }}个</span>
                </el-form-item>
                <el-form-item label="费用" :label-width="formLabelWidth">
                  <span>{{ totalFee }}</span>
                </el-form-item>
                <div class="notice">
                  <p>
                    您当前可支付余额为:<span>{{ paySum }}</span
                    >元,其中实际余额为:{{ actualBalance }},透支额度为{{
                      overdraw
                    }}
                  </p>
                  <p class="balance_not_enough" v-show="ifEnough">
                    您的账户余额不足，请立即充值。
                  </p>
                </div>
              </el-form>
              <div class="licencenotice">
                <ul>
                  <li>
                    增加、减少licence立即生效；减少licence不产生费用，请在即将到期的时候进行调整。
                  </li>
                </ul>
              </div>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogNumVisible = false" class="primary_btn"
                  >关 闭</el-button
                >
                <el-button
                  type="primary"
                  @click="confirmPayAdjustNum"
                  class="primary_btn"
                  >立即购买</el-button
                >
              </div>
            </el-dialog>
            <div v-show="show_robot_table">
              <div class="panel-heading">
                机器人服务
                <el-tooltip
                  content="提供在线客服的机器人功能"
                  placement="bottom"
                  effect="dark"
                >
                  <span class="tip"
                    ><i class="iconfont icon-tixingweizhi"></i
                  ></span>
                </el-tooltip>
              </div>
              <div class="zhichi_rebot_deal">
                <a :target="tmpl.target" @click="handleRobot">{{ tmpl.txt }}</a>
              </div>
              <el-table
                :data="tableData_robot"
                size="mini"
                style="width: 100%; display: block; margin-bottom: 20px"
              >
                <el-table-column prop="robot" label="智能机器人	" width="180">
                </el-table-column>
                <el-table-column prop="price" label="价格" width="180">
                </el-table-column>
                <el-table-column prop="wentry" label="词条数量">
                </el-table-column>
                <el-table-column prop="duration" label="时长">
                </el-table-column>
              </el-table>
            </div>
            <div>
              <div class="panel-heading">
                智能聊天机器人
                <span class="robotFresh" @click.stop="robotFresh">刷新</span>
              </div>
              <el-table
                :data="tableData_street"
                size="mini"
                style="width: 100%; display: block; margin-bottom: 50px"
              >
                <el-table-column prop="name" label="机器人套餐类型">
                </el-table-column>
                <el-table-column prop="used" label="当前使用词条数量">
                </el-table-column>
                <el-table-column prop="surplus" label="剩余词条量" width="180">
                </el-table-column>
                <el-table-column prop="warning" label="是否超过预警值">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import {
  getCacheByKey,
  getDateMonthSub,
  getBetweenDays,
  dateAdd,
  resetForm,
  Base64,
} from "@/utils/m7Utils";
import { checkform } from "@/utils/validate";
export default {
  name: "baseMessage",
  components: {},
  data() {
    let validatePhone = (rule, value, callback) => {
      if (value !== "") {
        let match = checkform(value, "Phone");
        if (match) {
          callback(new Error(this.$t(match)));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    let validateEmail = (rule, value, callback) => {
      if (value !== "") {
        let match = checkform(value, "Email");
        if (match) {
          callback(new Error(this.$t(match)));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    let validate1 = (rule, value, callback) => {
      if (value !== "") {
        let match = checkform(value, "Number3");
        if (match) {
          callback(new Error("只能为大于0的数字"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    let validate2 = (rule, value, callback) => {
      if (value !== "") {
        let match = checkform(value, "Number2");
        if (match) {
          callback(new Error("输入的金额有误"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    let validate3 = (rule, value, callback) => {
      if (value !== "") {
        let match = checkform(value, "Number3");
        if (match) {
          callback(new Error("不能为小数"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      base64Email: "",
      rules: {
        price: [{ validator: validate1, trigger: "blur" }],
      },
      rules1: {
        price: [{ validator: validate2, trigger: "blur" }],
      },
      rules2: {
        phone: [{ validator: validatePhone, trigger: "blur" }],
        email: [{ validator: validateEmail, trigger: "blur" }],
      },
      rules3: {
        licenceNumAdd: [{ validator: validate3, trigger: "blur" }],
      },
      rules4: {
        months: [{ validator: validate3, trigger: "blur" }],
      },
      rules5: {
        num: [{ validator: validate3, trigger: "blur" }],
      },
      dialogBalanceVisible: false,
      dialogLicenceVisible: false,
      dialog400Visible: false,
      dialogPayVisible: false,
      dialogAccountInfoVisible: false,
      dialogXufeiVisible: false,
      dialogNumVisible: false,
      dialodPayEnd: false,
      activeName2: "first",
      ifShowMore: true,
      identityStatus: "",
      oneLicenceShouldFee: 0,
      ifidentity: false,
      pbxlist: [],
      balance: "",
      paySum: 0,
      actualBalance: 0,
      showRenew: false,
      showRenewNum: false,
      showChangeStatus: false,
      cost: 0,
      perCost: 0,
      endDate: "",
      licenceNum: "",
      information: {
        companyName: "",
        name: "",
        linkManName: "",
        linkManPhone: "",
        linkManEmail: "",
        salesUser: {},
      },
      renewData: {},
      renewNumData: {},
      overdraw: 0,
      operation: ["续费"],
      row: {},
      accInfo: {},
      totalFee: 0,
      form1: {
        price: 0,
      },
      licenceForm: {
        type: "标准版",
        node: "",
        price: "",
        num: "",
      },
      bankPay: {
        price: "",
      },
      form4: {
        name: "",
        phone: "",
        email: "",
      },
      feeForm: {
        months: 1,
      },
      licenceNumForm: {
        licenceNumAdd: "",
      },
      formLabelWidth: "120px",
      formLabelWidth1: "80px",
      formLabelWidth2: "100px",
      tableData_licence: [],
      tableData_robot: [
        {
          robot: "基础版",
          price: "0元",
          wentry: "50条",
          duration: "永久",
        },
        {
          robot: "高级版",
          price: "12980元",
          wentry: "无限制",
          duration: "每年",
        },
      ],
      banks: [
        { name: "icbc_1301", id: "bank_ICBC", value: "ICBCB2C", show: true },
        { name: "ccb_1301", id: "bank_CCB", value: "CCB", show: true },
        { name: "cmb_1301", id: "bank_CMB", value: "CMB", show: true },
        { name: "abc_1301", id: "bank_ABC", value: "ABC", show: true },
        { name: "bcom_1301", id: "bank_BCOM", value: "COMM-DEBIT", show: true },
        { name: "gdb_1301", id: "bank_GDB", value: "GDB", show: true },
        { name: "boc_1301", id: "bank_BOC", value: "BOCB2C", show: true },
        { name: "cmbc_1301", id: "bank_CMBC", value: "CMBC", show: true },
        {
          name: "citic_1301",
          id: "bank_CITIC",
          value: "CITIC-DEBIT",
          show: true,
        },
        { name: "cib_1301", id: "bank_CIB", value: "CIB", show: true },
        { name: "ceb_1301", id: "bank_CEB", value: "CEB-DEBIT", show: true },
        { name: "post_1301", id: "bank_POSTGC", value: "POSTGC", show: true },
        { name: "spdb_1301", id: "bank_SPDB", value: "SPDB", show: false },
        { name: "pab_1301", id: "bank_SPABANK", value: "SPABANK", show: false },
        { name: "hzb_1301", id: "bank_HZCBB2C", value: "HZCBB2C", show: false },
        { name: "shb_1301", id: "bank_SHB", value: "SHBANK", show: false },
        { name: "nbcb_1301", id: "bank_NBBANK", value: "NBBANK", show: false },
      ],
      banks_enterprise: [
        { name: "icbc_1301", id: "bank_ICBCBTB", value: "ICBCBTB", show: true },
        { name: "ccb_1301", id: "bank_CCBBTB", value: "CCBBTB", show: true },
        { name: "cmb_1301", id: "bank_CMBBTB", value: "CMBBTB", show: true },
        { name: "abc_1301", id: "bank_ABCBTB", value: "ABCBTB", show: true },
        { name: "boc_1301", id: "bank_BOCBTB", value: "BOCBTB", show: true },
        { name: "spdb_1301", id: "bank_SPDBB2B", value: "SPDBB2B", show: true },
      ],
      banks_ali: [
        { name: "alipay", id: "bank_alipay", value: "alipay", show: true },
      ],
      ifEnough: false,
      tmpl: {
        txt: "",
        open: 1,
        data: "",
        href: "#",
        target: "_self",
      },
      ifAlert: true,
      balance_price: 0,
      show_robot_table: false,
      tableData_street: [],
      isAllowPay: "true", //   充值按钮能否使用
      licencePayType: "month", //    续费按年还是按月
      licencePayTypeUnit: "个月", //    续费按年还是按月  单位
    };
  },
  methods: {
    identitystatus() {
      let data = {};
      let pbx = [];
      if (
        this.$store.state.session.account &&
        this.$store.state.session.account.pbx
      ) {
        pbx = this.$store.state.session.account.pbx;
      }
      this.pbxlist = [];
      if (pbx.length > 0) {
        for (let i = 0; i < pbx.length; i++) {
          this.pbxlist.push(pbx[i].NickName);
        }
      }
      this.licenceForm.price =
        this.$store.state.session.account.serviceLicence / 10000;
      this.$store.dispatch("getAccountInfo", data).then((rep) => {
        if (rep.success) {
          let status = "";
          if (rep.row.salesUser === null) {
            rep.row.salesUser = "";
          }
          if (rep.row.balance <= 0) {
            this.ifAlert = false;
          }
          this.balance_price = rep.row.dialAlert;
          this.accInfo = rep.row;
          status = rep.row.identityStatus;
          let amount = parseFloat(rep.row.balance / 10000);
          let s = this.formatMoney(amount);
          this.balance = s;
          this.overdraw = rep.row.overdraw / 10000;
          this.paySum = this.formatMoney(
            parseFloat(rep.row.balance / 10000) + this.overdraw
          );
          this.actualBalance = parseFloat(rep.row.balance / 10000);
          this.information = {
            companyName: rep.row.companyName,
            name: rep.row.name,
            linkManName: rep.row.linkManName,
            linkManPhone: rep.row.linkManPhone,
            linkManEmail: rep.row.linkManEmail,
            salesUser: rep.row.salesUser,
            accountId: rep.row._id,
          };
          this.form4 = {
            name: this.information.linkManName,
            phone: this.information.linkManPhone,
            email: this.information.linkManEmail,
          };
          if (status === "deal") {
            this.identityStatus = "认证中";
          } else if (status === "failure") {
            this.identityStatus =
              "认证失败,原因：" + this.$store.state.session.account.auditMemo;
          } else if (status === "success") {
            this.identityStatus = "已认证";
          } else {
            this.identityStatus = "未认证";
            this.ifidentity = true;
          }
        }
      });
    },
    robotFresh() {
      this.getLittleStreetList();
    },
    cancleSetBalance() {
      this.dialogBalanceVisible = false;
      if (this.$refs["form1"]) {
        this.$refs["form1"].resetFields();
      }
    },
    setBalanceAlert() {
      this.dialogBalanceVisible = true;
      if (this.$refs["form1"]) {
        this.$refs["form1"].resetFields();
      }
      this.form1.price = this.balance_price;
    },
    addnewlicence() {
      this.dialogLicenceVisible = true;
      this.licenceForm.node = "";
      this.licenceForm.num = "1";
    },
    radioClick(index, bankname) {
      this.radioName = index;
      let JDradio = document
        .getElementsByClassName(bankname)
        [index].getElementsByClassName("jdradio")[0];
      if (JDradio && !JDradio.checked) {
        JDradio.checked = true;
      }
    },
    openAccountPay() {
      if (this.isAllowPay === "false") {
        this.$message({
          message: "您还未签约，禁止充值，如已签约请联系客服",
          type: "error",
        });
        return;
      }
      resetForm(this.bank);
      this.radioName = "";
      if (this.$refs["form"]) {
        this.$refs["form"].resetFields();
      }
      let inputs = document.getElementsByClassName("jdradio");
      let length = document.getElementsByClassName("jdradio").length;
      this.dialogPayVisible = true;
      this.ifShowMore = true;
      this.bankPay.price = "";
      for (let i = 0; i < this.banks.length; i++) {
        if (i > 11) {
          this.banks[i].show = false;
        }
      }
      for (let i = 0; i < length; i++) {
        inputs[i].checked = false;
      }
    },
    confirmAccountPay() {
      let inputs = document.getElementsByClassName("jdradio");
      let length = document.getElementsByClassName("jdradio").length;
      let index = "";
      for (let i = 0; i < length; i++) {
        if (inputs[i].checked === true) {
          index = i;
        }
      }
      if (
        checkform(this.bankPay.price, "Number2") ||
        this.bankPay.price === "" ||
        this.bankPay.price === "0"
      ) {
        this.$message({
          message: "请输入正确的金额",
          type: "error",
        });
      } else if (index === "") {
        this.$message({
          message: "支付方式必须选一项",
          type: "error",
        });
      } else {
        this.dialogPayVisible = false;
        let data = {
          action: "pay.bankPay",
          bank: inputs[index].value,
          data: "",
          flag: "pay",
          money: this.bankPay.price,
        };
        let bank = data.bank;
        if (!bank) {
          this.$message({
            message: "请选择一种支付方式",
            type: "error",
          });
          return;
        }
        let data2 = {
          method: "PaymentAdd",
          params: data,
          account: this.$store.state.session.user.account,
        };
        data =
          '{"action:":"pay.bankPay","data":"","flag":"pay","money":"' +
          this.bankPay.price +
          '","bank":"' +
          inputs[index].value +
          '"}';
        data2 =
          '{"method":"PaymentAdd","params":' +
          data +
          ',"account":"' +
          this.$store.state.session.user.account +
          '"}';
        data2 = "data=" + encodeURIComponent(data2);
        let data1 = "action=pay.bankPay";
        let data3 = "flag=pay";
        let url = "/public2cc?" + data1 + "&" + data2 + "&" + data3;
        window.open(url);
        this.dialodPayEnd = true;
      }
    },
    finishbankpay() {
      let data = this.$store.state.session.user.account;
      this.$store.dispatch("finishBankPay", data).then((rep) => {
        if (rep.success) {
          let account = rep.row;
          account.balanceDesc = this.formatMoney(account.balance / 10000);
          this.balance = account.balanceDesc;
          this.dialodPayEnd = false;
        } else {
          this.$message({
            message: "服务异常",
            type: "error",
          });
        }
      });
    },
    licenceChange(val) {
      this.licenceForm.num = val;
    },
    handleClick() {},
    // 保留两位小数
    format2Decimal(amount) {
      var i = parseFloat(amount);
      if (isNaN(i)) {
        i = 0.0;
      }
      var minus = "";
      if (i < 0) {
        minus = "-";
      }
      i = Math.abs(i);
      i = parseInt((i + 0.005) * 100);
      i = i / 100;
      var s = new String(i);
      if (s.indexOf(".") < 0) {
        s += ".00";
      }
      if (s.indexOf(".") == s.length - 2) {
        s += "0";
      }
      s = minus + s;
      return s;
    },
    handleChangeNum(val) {
      let data = this.renewNumData;
      this.licenceNumForm.licenceNumAdd = val;
      data.num = this.licenceNumForm.licenceNumAdd;
      // this.totalFee = this.calculateLicenceFeeNew(data)
      console.log(this.oneLicenceShouldFee, this.renewNumData.changeNum);
      if (this.licenceNumForm.licenceNumAdd - this.licenceNum > 0) {
        this.totalFee = this.format2Decimal(
          this.oneLicenceShouldFee *
            (this.licenceNumForm.licenceNumAdd - this.licenceNum)
        );
      } else {
        this.totalFee = 0;
      }
    },
    handleChange(val) {
      this.feeForm.months = val;
      if (this.licencePayType === "year") {
        this.cost = this.licenceNum * this.perCost * this.feeForm.months * 12;
      } else {
        this.cost = this.licenceNum * this.perCost * this.feeForm.months;
      }
    },
    formatTrueFee(number) {
      number = number || 0;
      return number / 10000;
    },
    showMore(ifMore) {
      let self = this;
      for (let i = 0; i < self.banks.length; i++) {
        self.ifShowMore = !ifMore;
        if (i > 11) {
          self.banks[i].show = ifMore;
        }
      }
      if (this.radioName !== "") {
        document.getElementsByClassName("jdradio")[
          this.radioName
        ].checked = true;
      }
    },
    setBalance() {
      let data = {
        dialAlert: this.form1.price,
        _id: this.$store.state.session.user.account,
      };
      if (checkform(data.dialAlert, "Number3")) {
        this.$message({
          message: "请输入正确的金额",
          type: "error",
        });
        return;
      }
      this.balance_price = this.form1.price;
      this.$store.dispatch("updateNotifySet", data).then((rep) => {
        if (rep.success) {
          this.dialogBalanceVisible = false;
          this.$message({
            message: "预警值设置成功",
            type: "success",
          });
        }
      });
    },
    setAccountInfo() {
      if (checkform(this.form4.phone, "Phone")) {
        this.$message({
          message: "电话格式输入错误",
          type: "error",
        });
        return;
      } else if (checkform(this.form4.email, "Email")) {
        this.$message({
          message: "邮箱格式输入错误",
          type: "error",
        });
        return;
      } else if (this.form4.name === "") {
        this.$message({
          message: "联系人不能为空",
          type: "error",
        });
        return;
      } else if (this.form4.email === "") {
        this.$message({
          message: "邮箱不能为空",
          type: "error",
        });
        return;
      } else if (this.form4.phone === "") {
        this.$message({
          message: "电话不能为空",
          type: "error",
        });
        return;
      }
      let data = {
        _id: this.$store.state.session.user.account,
        linkManName: this.form4.name,
        linkManPhone: this.form4.phone,
        linkManEmail: this.form4.email,
      };
      this.$store.dispatch("updateAccountInfo", data).then((rep) => {
        if (rep.success) {
          let row = rep.row;
          this.information.linkManName = row.linkManName;
          this.information.linkManPhone = row.linkManPhone;
          this.information.linkManEmail = row.linkManEmail;
          this.dialogAccountInfoVisible = false;
        }
      });
    },
    redirectUcenter(dest) {
      let data = {
        sid: this.$store.state.session.user._id,
        dest: dest,
      };
      this.$store.dispatch("redirectcenter", data).then((rep) => {
        if (rep.success) {
          let url = rep.url;
          window.open(url, "_newtab");
        } else {
          this.$message({
            message: rep.message || "服务异常",
            type: "error",
          });
        }
      });
    },
    addLicence() {
      if (this.licenceForm.node === "") {
        this.$message({
          message: "节点必须填写",
          type: "error",
        });
        return;
      } else if (checkform(this.licenceForm.num, "Number3")) {
        this.$message({
          message: "数量不能为小数",
          type: "error",
        });
        return;
      } else {
        this.dialogLicenceVisible = false;
        let data = {
          flag: "buyLicence",
          licencePrice: this.licenceForm.price.toString(),
          licenceType: "service",
          num: this.licenceForm.num,
          pbx: this.licenceForm.node,
          _id: "",
        };
        this.$store.dispatch("addLicence", data).then((rep) => {
          if (!rep.success) {
            this.getLicenceList("");
          }
        });
      }
    },
    formatMoney(amount) {
      if (isNaN(amount)) {
        amount = 0.0;
      }
      let minus = "";
      if (amount < 0) {
        minus = "-";
      }
      amount = parseInt((Math.abs(amount) + 0.005) * 100) / 100;
      let s = amount.toString();
      if (s.indexOf(".") < 0) {
        s += ".00";
      } else if (s.indexOf(".") === s.length - 2) {
        s += "0";
      }
      s = minus + s;
      return s;
    },
    getLittleStreetList() {
      this.tableData_street = [];
      const data = {
        account: this.$store.state.session.user.account || "",
      };
      this.$store.dispatch("getLittleStreetList", data).then((res) => {
        if (res && res.success) {
          console.log(res);
          for (let i = 0; i < res.list.length; i++) {
            const _obj = {
              name: this.$t("config.account." + res.list[i].name),
              surplus: res.list[i].surplus,
              used: res.list[i].used,
              warning:
                res.list[i].warning === true
                  ? "是"
                  : res.list[i].warning === false
                  ? "否"
                  : "",
            };
            this.tableData_street.push(_obj);
          }
        }
      });
    },
    getLicenceList(data) {
      let cc = this.$store.state.session.account;
      let self = this;
      this.tableData_licence = [];
      this.$store.dispatch("getAllLicenceList", data).then((res) => {
        if (res && res.success) {
          let list = res.list;
          for (let i = 0; i < list.length; i++) {
            let lSTATUS = "";
            let lPRICE = "";
            let lTYPE = "";
            this.showRenew = false;
            this.showRenewNum = false;
            this.showChangeStatus = false;
            if (list[i].status === "use") {
              lSTATUS = "在用";
            } else if (list[i].status === "try") {
              lSTATUS = "试用";
            } else if (list[i].status === "present") {
              lSTATUS = "赠送";
            } else if (list[i].status === "stop") {
              lSTATUS = "停用";
            }
            if (list[i].licenceType === "enterprise") {
              lPRICE = this.formatTrueFee(cc.callinLicence);
            } else if (list[i].licenceType === "monitor") {
              lPRICE = this.formatTrueFee(cc.monitorLicence);
            } else if (list[i].licenceType === "service") {
              lPRICE = this.formatTrueFee(cc.serviceLicence);
            } else if (list[i].licenceType === "outcall") {
              lPRICE = "0";
            } else if (list[i].licenceType === "service_p") {
              lPRICE = "0";
            } else if (list[i].licenceType === "outcallSpecial") {
              lPRICE = this.formatTrueFee(cc.electricLicence);
            } else if (list[i].licenceType === "business") {
              lPRICE = this.formatTrueFee(cc.standardElectricLicence);
            } else if (list[i].licenceType === "bigdata") {
              lPRICE = this.formatTrueFee(cc.bigdataLicence);
            }
            lPRICE = lPRICE + "元";
            if (list[i].licenceType !== "service_p") {
              this.showRenew = true;
            }
            if (
              list[i].licenceType !== "outcall" &&
              list[i].licenceType !== "service_p"
            ) {
              this.showRenewNum = true;
            }
            if (list[i].licenceType !== "outcall") {
              this.showChangeStatus = true;
            }
            if (list[i].licenceType === "bigdata" || list[i].status === "try") {
              this.showRenewNum = false;
            }
            let _obj = getCacheByKey(
              "licenceType",
              "code_value",
              list[i].licenceType
            );
            if (_obj) {
              lTYPE = _obj.code_name;
              self.tableData_licence.push({
                _id: list[i]._id,
                pbx: list[i].pbx,
                licenceType: list[i].licenceType,
                type: lTYPE,
                price: lPRICE,
                agentNum: list[i].num,
                status: lSTATUS,
                deadline: list[i].endDate,
                beginDate: list[i].beginDate,
                createTime: list[i].createTime,
                statusEn: list[i].status,
                operation: {
                  showRenew: this.showRenew,
                  showRenewNum: this.showRenewNum,
                  showChangeStatus: this.showChangeStatus,
                },
              });
            }
          }
        } else {
          this.$message({
            message: "服务异常",
            type: "error",
          });
        }
      });
    },
    confirmPay() {
      let data = this.renewData;
      data.product = "cc";
      data.month = this.feeForm.months.toString();
      this.calculateLicenceFee(data);
      if (this.licencePayType === "year") {
        data.month = Number(data.month) * 12;
        data.month = data.month.toString();
        data.totalFee = data.totalFee * 12;
      }
      if (parseInt(data.num, 10) < 1) {
        this.$message({
          message: "licence数量最小为1",
          type: "error",
        });
        return;
      }
      if (parseFloat(data.balance) < 0) {
        this.$message({
          message: "您的账户已欠费，请先充值",
          type: "error",
        });
        return;
      }
      if (checkform(this.feeForm.months, "Number3")) {
        this.$message({
          message: "时长不能为小数",
          type: "error",
        });
        return;
      }
      this.balancePay(data);
      this.dialogXufeiVisible = false;
    },
    confirmPayAdjustNum() {
      let data = this.renewNumData;
      data.num = data.num.toString();
      data.product = "cc";
      this.calculateLicenceFeeNew(data);
      if (data.changeNum === 0) {
        this.$message({
          message: "数量没有调整",
          type: "error",
        });
        return;
      }
      let balance = parseFloat(data.balance);
      if (balance < 0) {
        this.$message({
          message: "您的账户已欠费，请先充值",
          type: "error",
        });
        return;
      }
      if (checkform(this.licenceNumForm.licenceNumAdd, "Number3")) {
        this.$message({
          message: "数量不能为小数",
          type: "error",
        });
        return;
      }
      data.totalFee = this.totalFee;
      if (data.totalFee > 0) {
        this.balancePay(data, true);
        this.dialogNumVisible = false;
      } else {
        let flag = data.flag;
        let changeNum = parseInt(data.changeNum, 10);
        if (data.status !== "try" && flag === "adjustLicenceNum") {
          if (changeNum < 0) {
            this.$confirm(
              "减少licence立即生效，不会退还相关费用，为减少不必要的损失，建议您即将到期的时候进行此操作，确认要继续吗",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                cancelButtonClass: "primary_btn",
                confirmButtonClass: "primary_btn",
                type: "warning",
              }
            )
              .then(() => {
                this.$store
                  .dispatch("updateLicenceAndBalance", data)
                  .then((res) => {
                    if (res.success) {
                      this.getLicenceList({});
                      this.$message({
                        type: "success",
                        message: "减少成功!",
                      });
                    } else {
                      this.$message({
                        message: res.message || "服务异常",
                        type: "error",
                      });
                    }
                  });
                this.dialogNumVisible = false;
                return;
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "已取消",
                });
                this.dialogNumVisible = false;
                return;
              });
          } else {
            this.$store
              .dispatch("updateLicenceAndBalance", data)
              .then((res) => {
                if (res.success) {
                  this.getLicenceList({});
                  this.dialogNumVisible = false;
                } else {
                  this.dialogNumVisible = false;
                  this.$message({
                    message: res.message || "服务异常",
                    type: "error",
                  });
                }
              });
          }
        } else {
          this.$store.dispatch("updateLicenceAndBalance", data).then((res) => {
            if (res.success) {
              this.getLicenceList({});
              this.dialogNumVisible = false;
            } else {
              this.dialogNumVisible = false;
              this.$message({
                message: res.message || "服务异常",
                type: "error",
              });
            }
          });
        }
      }
    },
    queryRobotService() {
      let data = {
        account: this.$store.state.session.user.account,
      };
      this.$store.dispatch("queryRobot", data).then((res) => {
        if (res.success) {
          let robot = res.data;
          this.tmpl = {
            txt: "开通",
            open: 1,
            data: "智齿",
            href: "#",
            target: "_self",
          };
          if (robot && robot._id) {
            this.tmpl = {
              txt: "配置",
              open: 0,
              data: robot._id,
              href: "#",
              target: "_blank",
            };
            this.show_robot_table = true;
          } else if (this.$store.state.session.user.type === "admin") {
            this.show_robot_table = true;
          }
        } else {
          this.$message({
            message: res.message || "服务异常",
            type: "error",
          });
        }
      });
    },
    balancePay(data, flag) {
      let api = flag ? "updateLicenceAndBalance" : "LicenceBalancePay";
      this.$store.dispatch(api, data).then((res) => {
        if (res.success) {
          let aid = this.$store.state.session.user.account;
          this.$store.dispatch("finishPay", aid).then((rep) => {
            if (rep.success) {
              let acc = rep.row;
              let balanceDesc = this.formatMoney(acc.balance / 10000);
              this.accInfo = acc;
              this.balance = balanceDesc;
              this.getLicenceList({});
            } else {
              if (rep.code === "404") {
                this.$message({
                  message: "该号码已经超时释放或被其他人抢用",
                  type: "error",
                });
              } else {
                this.$message({
                  message: rep.message || "支付异常",
                  type: "error",
                });
              }
            }
          });
        }
      });
    },
    renew(index, row) {
      this.feeForm.months = 1;
      this.dialogXufeiVisible = true;
      let cc = this.$store.state.session.account;
      let data = {
        _id: this.tableData_licence[index]._id,
      };
      this.endDate = this.tableData_licence[index].deadline;
      this.licenceNum = this.tableData_licence[index].agentNum;
      this.perCost = parseFloat(
        this.tableData_licence[index].price.split("元")[0]
      );
      if (this.licencePayType === "year") {
        this.cost = this.licenceNum * this.perCost * this.feeForm.months * 12;
      } else {
        this.cost = this.licenceNum * this.perCost * this.feeForm.months;
      }
      let data1 = {
        account: this.$store.state.session.user.account,
        balance: this.paySum.toString(),
        beginDate: this.tableData_licence[index].beginDate,
        endDate: this.endDate,
        flag: "renewLicence",
        createTime: this.tableData_licence[index].createTime,
        licencePrice: this.perCost.toString(),
        licenceType: this.tableData_licence[index].licenceType,
        month: this.feeForm.months.toString(),
        num: this.licenceNum.toString(),
        pbx: this.tableData_licence[index].pbx,
        status: this.tableData_licence[index].statusEn,
        _id: this.tableData_licence[index]._id,
      };
      this.renewData = data1;
      this.$store.dispatch("getLicenceById", data).then((rep) => {
        if (rep.success) {
          let license = rep.license;
          if (license.licenceType === "outcall") {
            this.perCost = cc.calloutLicence / 10000;
            license.calloutMinute = cc.calloutMinute || 0;
            this._setAccBalance(license);
          } else {
            if (license.licenceType === "enterprise") {
              this.perCost = cc.callinLicence / 10000;
            } else if (license.licenceType === "monitor") {
              this.perCost = cc.monitorLicence / 10000;
            } else if (license.licenceType === "service") {
              this.perCost = cc.serviceLicence / 10000;
            }
            if (!license.numNew) {
              license.numNew = license.num;
              this.licenceNum = license.numNew;
            }
            this._setAccBalance(license);
            this.totalFee = license.totalFee;
          }
        } else {
          this.$message({
            message: "服务异常",
            type: "error",
          });
        }
      });
    },
    renewNum(index, row) {
      this.dialogNumVisible = true;
      let cc = this.$store.state.session.account;
      let data = {
        _id: this.tableData_licence[index]._id,
      };
      this.endDate = this.tableData_licence[index].deadline;
      this.licenceNum = this.tableData_licence[index].agentNum;
      this.licenceNumForm.licenceNumAdd = this.licenceNum;
      this.totalFee = 0;
      this.perCost = parseFloat(
        this.tableData_licence[index].price.split("元")[0]
      );
      this.cost = this.licenceNum * this.perCost * this.feeForm.months;
      let data1 = {
        discountOriginal: this.tableData_licence[index].discountOriginal
          ? this.tableData_licence[index].discountOriginal
          : "1",
        discount: this.tableData_licence[index].discount
          ? this.tableData_licence[index].discount
          : "1",
        account: this.$store.state.session.user.account,
        balance: this.paySum.toString(),
        beginDate: this.tableData_licence[index].beginDate,
        endDate: this.endDate,
        flag: "adjustLicenceNum",
        createTime: this.tableData_licence[index].createTime,
        licencePrice: this.perCost.toString(),
        licenceType: this.tableData_licence[index].licenceType,
        oldNum: this.licenceNum.toString(),
        num: this.licenceNumForm.licenceNumAdd.toString(),
        pbx: this.tableData_licence[index].pbx,
        status: this.tableData_licence[index].statusEn,
        _id: this.tableData_licence[index]._id,
      };
      this.renewNumData = data1;
      this.$store.dispatch("getLicenceById", data).then((rep) => {
        if (rep.success) {
          this.oneLicenceShouldFee = rep.oneLicenceShouldFee;
          let license = rep.license;
          if (license.licenceType === "enterprise") {
            this.perCost = cc.callinLicence / 10000;
          } else if (license.licenceType === "monitor") {
            this.perCost = cc.monitorLicence / 10000;
          } else if (license.licenceType === "service") {
            this.perCost = cc.serviceLicence / 10000;
          }
          if (!license.numNew) {
            license.numNew = license.num;
            this.licenceNum = license.numNew;
          }
          this._setAccBalance(license);
        } else {
          this.$message({
            message: "服务异常",
            type: "error",
          });
        }
      });
    },
    _setAccBalance(data) {
      let accinfo = this.accInfo;
      let overdraw = accinfo.overdraw || 0;
      let total = accinfo.balance + overdraw;
      this.paySum = total / 10000;
      this.overdraw = overdraw / 10000;
      this.actualBalance = accinfo.balance / 10000;
    },
    calculateLicenceFee(data) {
      let month = parseInt(data.month, 10) || 1;
      let num = parseInt(data.num, 10) || 1;
      let price = parseFloat(data.licencePrice);
      let totalFee = Math.round(price * month * num * 10000) / 10000;
      data.totalFee = totalFee;
      return data.totalFee;
    },
    calculateLicenceFeeNew(data) {
      //        let licenceType = data.licenceType
      let oldNum = parseInt(data.oldNum, 10) || 0;
      let num = parseInt(data.num, 10) || 0;
      let price = parseFloat(data.licencePrice);
      let endDate = data.endDate;
      let changeNum = num - oldNum || 0;
      let totalFee = 0;
      if (data.status !== "try") {
        if (changeNum > 0) {
          let nowDate = new Date();
          console.log(nowDate, endDate, price, changeNum, totalFee);
          totalFee = this.FeeHandler(
            nowDate,
            endDate,
            price,
            changeNum,
            totalFee
          );
        }
      }
      data.changeNum = changeNum;
      data.totalFee = this.formatMoney(totalFee);
      return data.totalFee;
    },
    FeeHandler(nowDate, endDate, price, changeNum, totalFee) {
      if (getBetweenDays(endDate, this.getDateDesc(nowDate)) < 1) {
        return totalFee;
      }
      let months = getDateMonthSub(nowDate, endDate);
      if (months >= 1) {
        totalFee += changeNum * price * months;
      }
      let date2 = dateAdd("M", months, nowDate);
      var days = getBetweenDays(endDate, this.getDateDesc(date2));
      totalFee += (days / 30) * price * changeNum;
      return totalFee;
    },
    getDateDesc(date) {
      let year = date.getFullYear();
      let month = date.getMonth();
      let day = date.getDate();
      month = month + 1 > 9 ? month + 1 : "0" + (month + 1);
      day = day > 9 ? day : "0" + day;
      return year + "-" + month + "-" + day;
    },
    handleRobot() {
      if (this.tmpl.open) {
        let data = {
          robot_type: this.tmpl.data,
        };
        this.$store.dispatch("saveRobot", data).then((rep) => {
          if (rep.success) {
            this.$message({
              message: "开通智齿机器人客服成功",
              type: "success",
            });
            if ("robotConfig" in this.$m7cache()) {
              this.$deleteCache("robotConfig");
            }
            this.queryRobotService();
          } else {
            this.$message({
              message: rep.message,
              type: "error",
            });
          }
        });
      } else {
        let data = {
          _id: this.tmpl.data,
        };
        this.$store.dispatch("showRobotLoginUrl", data).then((res) => {
          if (res.success) {
            let robotLoginUrl = res.data;
            document
              .getElementsByClassName("zhichi_rebot_deal")[0]
              .getElementsByTagName("a")[0].href = robotLoginUrl;
          } else {
            this.$message({
              message: "登录链接获取失败",
              type: "error",
            });
          }
        });
      }
    },
    editInfo() {
      this.dialogAccountInfoVisible = true;
      if (this.$refs["infoForm"]) {
        this.$refs["infoForm"].resetFields();
      }
      this.form4.name = this.information.linkManName;
      this.form4.phone = this.information.linkManPhone;
      this.form4.email = this.information.linkManEmail;
    },
  },
  beforeMount() {
    this.identitystatus();
    this.$store.dispatch("queryPlatformAccount", {}).then((rep) => {
      if (rep.success) {
        this.isAllowPay = rep.data.isAllowPay;
      }
    });
  },
  mounted() {
    this.base64Email = Base64.decode("c2VydmljZUA3bW9vci5jb20=");
    this.getLittleStreetList();
    this.queryRobotService();
    this.getLicenceList({});
    this.licencePayType = this.$store.state.session.account.licencePayType
      ? this.$store.state.session.account.licencePayType.licencePayType
      : "month";
    if (this.licencePayType === "year") {
      this.licencePayTypeUnit = "年";
    } else {
      this.licencePayTypeUnit = "个月";
    }
  },
};
</script>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
  .base-content
    /*height calc(100vh - 150px)*/
    height calc(100vh - 53px)
    overflow auto
    .account_base
      margin 20px 35px 0
      .custom_wallet
        border 1px solid #e6e6e6
        border-top 0
        margin-top 10px
        padding 10px 6%
        background #e6e6e6
        line-height 30px
        .custom_alance
          padding 5px 0 10px
          .accFee
            color #f0ad4e
            font-size 28px
          .accOweFee
            color #ff6c65
            font-size 28px
        .bank-list
          margin 20px 0px 0px 20px
          .bank1,.bank2,.bank3
            border 1px solid #ddd
            background-color #fff
            float left
            padding 6px
            width 160px
            margin-right 10px
            margin-bottom 10px
            cursor pointer
            line-height 20px
            .jdradio
              margin 0 11px 0 6px
              cursor pointer
            img
              vertical-align middle
              cursor pointer
      .field
        display inline-block
        vertical-align top
      .info
        display inline-block
        vertical-align top
      .text_action_blue
        color $c-main
        margin-left 11px
        font-size 14px
        cursor pointer
      .pull-right
        float right
        .dentity
          color #fff
          line-height 18px
          display inline-block
          padding 0 3px
          margin-right 3px
          background #e6e6e6
        .img_action_edit
          width 16px
          height 16px
          cursor pointer
          line-height 16px
          .icon-beizhu
            color $c-main
      .base_info_inner
        border 1px solid #e6e6e6
        margin-bottom 10px
        padding 10px 6%
        color #8c8c8c
        line-height 24px
        .item_col .field, .item_col .info
          font-size 14px
          display inline-block
          vertical-align top
      .alert-block
        line-height 18px
        word-break break-all
        padding 8px 14px
      .alert
        border-radius 1px
        color #c09853
        padding 8px 35px 8px 14px
        margin-bottom 20px
        text-shadow 0 1px 0 rgba(255,255,255,0.5)
        background-color #fcf8e3
        border 1px solid #fbeed5
        -webkit-border-radius 4px
        -moz-border-radius 4px
        border-radius 4px
      .sub-right
        padding 0 0 12px 34px
        border-left 1px solid #e6e6e6
        margin-bottom 50px
        .panel-info
          min-height 440px
          .panel-heading
            height 25px
            padding-bottom 8px
            color #454545
            line-height 25px
            .licence
              line-height 22px
              padding 0 5px
            .licence:before
              content "\2b"
              font-size 22px
              font-weight bold
              vertical-align middle
              font-family Arial
          .phoneNumPage
            margin-bottom 10px
      .yuan
        padding 5px 10px 0
      .headMargin
        margin-left 10px
        font-size 12px
      .recharge_amount
        margin 5px 10px
      .pay-more
        width 170px
        margin-left 20px
        .link-more
          height 39px
          line-height 39px
          width 100%
          border: 1px dotted #ccc
          display: inline-block
          text-align: center
          padding: 1px
          .icon-zhankai1,.icon-shouqi
            font-size 12px
            padding 0 5px 0
      .opeLink
        margin-right 10px
      .licence_pay
        .well
          min-height 20px
          margin-bottom 20px
          background-color #f5f5f5
          border 1px solid #e3e3e3
          border-radius 4px
          box-shadow inset 0 1px 1px rgba(0, 0, 0, 0.05)
          padding 0 19px
          font-size 13px
          h2
            font-size 30px
            font-weight bold
            line-height 40px
            small
              font-weight normal
              font-size 17px
              color $cf-gray5
      .text-primary
        color $c-main
      .text-danger
        color #b94a48
      .text-muted
        color $cf-gray5
      .month
        vertical-align text-bottom
        display inline-block
        text-indent 10px
        font-size 12px
      .notice
        margin-bottom: 15px
        width 100%
        text-align center
        p
          line-height 36px
        .balance_not_enough
          dispaly none
          color red
      .licencenotice
        color #3a87ad
        background-color #d9edf7
        border-color #bce8f1
        padding 8px 35px 8px 14px
        margin-bottom 20px
        text-shadow 0 1px 0 rgba(255,255,255,0.5)
        border 1px solid #bce8f1
        -webkit-border-radius 4px
        -moz-border-radius 4px
        border-radius 4px
      .zhichi_rebot_deal
        height 48px
        line-height 48px
        border 1px solid #e7e7eb
        border-bottom none
        padding-left 17px
      .tip
        display inline-block
        height 16px
        width 16px
        text-align center
        line-height 16px
        margin 0 12px
        position relative
        top -1px
        font-size 10px
        .iconfont
          font-size 10px
          color $c-main
        .icon-tixingweizhi
          border 1px solid $c-main
          border-radius 50%
          display inline-block
          height 16px
          width 16px
          text-align center
          line-height 16px
          position relative
          top -1px
          font-size 10px
      .pay_end
        p
          font-size 14px
          margin-bottom 15px
          text-align center
.robotFresh
  color $c-main
  cursor pointer
.price-tip
  font-size 12px
  margin-left 16px
  color #b94a48
</style>
